package org.example.spring.aop.annotation;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.util.StopWatch;
//将这里的Order(1)为顺序逻辑1，改为Order(10)为顺序逻辑2
@Order(10)
@Aspect
@Component
public class TimingAspect {
    private static final Logger log = org.slf4j.LoggerFactory.getLogger(TimingAspect.class);

    @Around("@annotation(org.example.spring.aop.annotation.Timing)")
    public Object recordTime(ProceedingJoinPoint joinPoint) throws Throwable {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        Object result = joinPoint.proceed();
        stopWatch.stop();
        System.out.println("方法" + joinPoint.getSignature().getName() + "执行时间" + stopWatch.getTotalTimeMillis() + "ms");
        return result;
    }
}
